package scalaLearning.part8

class ComparInt(x: Int, y: Int) {
  def bigger(): Unit = {
    if (x > y)
      x else y
  }
}

class ComparLong(x: Long, y: Long) {
  def bigger(): Unit = {
    if (x > y)
      x else y
  }
}

class ComparComm[T <% Comparable[T]](o1:T,o2:T){
  def bigger() ={
    if (o1.compareTo(o2) > 0) o1 else o2
  }
}

object ViewBoundDemo1 {
  def main(args: Array[String]): Unit = {
    val comparInt = new ComparInt(1,2)  //Int  视图界定  Integer  scala隐式转换包
    println(comparInt.bigger())
    val comparLong = new ComparLong(3L,2L)
    println(comparLong.bigger())

    //传入Int报错，因为Int不是Comparable的子类
    //传入Integer可以
    //如何将Int转化为Integer？就用到了隐式转换。 <%
    val comm = new ComparComm[Int](1,3)
    println(comm.bigger())
  }

}
